package com.example.webtest;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.word.PicType;
import cn.hutool.poi.word.Word07Writer;
import com.example.webtest.model.DistributionMember;

import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

/**
 * @author zhuxy@yuntai.com
 * @description
 * @date 2022/6/27-10:32
 */
public class TestMain {
    public static void main(String[] args) throws FileNotFoundException {
//        createWord();
        implExcel();
    }

    /**
     * 创建word
     */
    public static void createWord() throws FileNotFoundException {
        Word07Writer writer = new Word07Writer();
        File file = new File("C:/Users/Administrator/Desktop/文件/图片/商品1.png");
        InputStream in = new FileInputStream(file);
        writer.addPicture(in, PicType.PNG, "测试", 200, 200);
        writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分", "我是第二部分");
        // 写出到文件
        writer.flush(FileUtil.file("C:/Users/Administrator/Desktop/文件/图片/wordWrite.docx"));
        // 关闭
        writer.close();
    }

    /**
     * 导入excel
     */
    public static void implExcel() throws FileNotFoundException {
//        InputStream stream = URLUtil.getStream(URLUtil.url("xxx"));
        File file = new File("C:/Users/Administrator/Desktop/推广员-导入模板.xlsx");
        FileInputStream in = new FileInputStream(file);
        ExcelReader reader = ExcelUtil.getReader(in);
        List<DistributionMember> read = reader.read(0, 2, Integer.MAX_VALUE, DistributionMember.class);
        System.out.println(read.toString());

    }


}
